/*
 * A modified QuizWidget which shows Phrase icons instead of text.
 */

#include <QtGui>

#include "quiziconwidget.h"

// create a pushbutton for a Phrase which displays the Phrase's icon
QAbstractButton* QuizIconWidget::createButton(const Phrase* phrase) {
	//  load the phrase icon
	QIcon icon(phrase->getIconFilename());
	QPushButton *button =  new QPushButton(icon, QString("")); // no string content for button
	button->setIconSize(QSize(ICON_SIZE,ICON_SIZE));
	return button;
}

// lay the buttons onto an (n x 2) grid layout
QLayout* QuizIconWidget::createOptionsLayout(const QList<QAbstractButton*> options) {
	// create grid layout
	QGridLayout* layout = new QGridLayout();
	layout->setSpacing(45);
	QListIterator<QAbstractButton*> it(options);
	// iterate through option buttons
	bool col = 0;
	int row = 0;
	while (it.hasNext()) {
		int c = col ? 0 : 1;
		layout->addWidget(it.next(), row, c); 
		// alternate columns
		if (!(col = !col)) {
			++row;
		}
	}

	return layout;
}
